/* 
 * File:   NodeMinus.h
 * Author: user
 *
 * Created on December 31, 2012, 7:01 PM
 */

#ifndef NODEMINUS_H
#define	NODEMINUS_H

#include <QtGui>
#include "Node.h"

class NodeMinus : public Node {

    Q_OBJECT

public:
    NodeMinus()
    : Node(QString("minus"), 2, QString("-")) {
        // add the layout
        QHBoxLayout* layout = new QHBoxLayout(this);
        layout->setSpacing(1);
        layout->setContentsMargins(1, 1, 1, 1);

        // add the label
        QLabel* lab = new QLabel();
        lab->setText(getNodeValue());
        layout->addWidget(lab);
    }

    QString toCasString() const {
        Q_ASSERT_X(getLeftChild() != 0, "Node::toCasString",
                "Could not find left hand child node.");
        Q_ASSERT_X(getRightChild() != 0, "Node::toCasString",
                "Could not find right hand child node.");
        Q_ASSERT_X(numChildren() == 2, "Node::toCasString",
                "Expected two children.");
        QString str;
        str.append("(");
        if (getLeftChild()->getNodeType() == "empty") str.append("0");
        else str.append(getLeftChild()->toCasString());
        str.append(getNodeValue());
        if (getRightChild()->getNodeType() == "empty") str.append("0");
        else str.append(getRightChild()->toCasString());
        str.append(")");
        return str;
    }

};


#endif	/* NODEMINUS_H */

